package br.indt.framework.log;

//#ifdef LOGS
import net.sf.microlog.core.Logger;
import net.sf.microlog.core.LoggerFactory;
import net.sf.microlog.midp.bluetooth.BluetoothSerialAppender;
//#endif

/**
 * This class wraps the Microlog API functionalities. This class allow project
 * enable, disable and discard the API when going to production environment, 
 * where is no longer make sense keep it.
 * 
 * @author ext-alessandro.barbosa@nokia.com
 */
public class MicrologWrapper {
	
    //#ifdef LOGS
    private Logger log;
    //#endif

    /**
     * Private class constructor to ensure that all instances be created by
     * getLogger factory static method.
     * 
     * @param clazz
     */
    private MicrologWrapper(Class clazz){
        //#ifdef LOGS
        log = LoggerFactory.getLogger(clazz);
        //#endif
    }

    /**
     * Factory method to get new instances of MicrologWrapper.
     * 
     * @param clazz
     * @return
     */
    public static MicrologWrapper getLogger(Class clazz){
        return new MicrologWrapper (clazz);	
    }

    /**
     * Outputs microlog debug level messages
     * 
     * @param message Message to be logged.
     */
    public void debug (String message){
        //#ifdef LOGS
        log.debug(message);
        //#endif
    }

    /**
     * Outputs microlog debug level messages with exception thrown nested.
     * 
     * @param message Message to be logged.
     */
    public void debug (String message, Throwable t){
        //#ifdef LOGS
        log.debug(message, t);
        //#endif
    }

    /**
     * Outputs microlog error level messages
     * 
     * @param message Message to be logged.
     */
    public void error (String message){
        //#ifdef LOGS
        log.error(message);	
        //#endif
    }

    /**
     * Outputs microlog error level messages with exception thrown nested.
     * 
     * @param message Message to be logged.
     */
    public void error (String message, Throwable t){
        //#ifdef LOGS
        log.error(message, t);
        //#endif
    }

    /**
     * Outputs microlog fatal level messages
     * 
     * @param message Message to be logged.
     */
    public void fatal (String message){
        //#ifdef LOGS
        log.fatal(message);
        //#endif
    }

    /**
     * Outputs microlog fatal level messages with thrown exeception nested.
     * 
     * @param message Message to be logged.
     */
    public void fatal (String message, Throwable t){
        //#ifdef LOGS
        log.fatal(message, t);
        //#endif
    }

    /**
     * Outputs microlog info level messages
     * 
     * @param message Message to be logged.
     */
    public void info (String message){
        //#ifdef LOGS
         log.info(message);
        //#endif
    }
    
    /**
     * Outputs microlog info level messages with thrown exception nested.
     * 
     * @param message Message to be logged.
     */
    public void info (String message, Throwable t){
        //#ifdef LOGS
        log.info(message, t);
        //#endif
    }

    /**
     * Establish connection with a external bluetooth server. This method
     * enable developers to easily send log messages from mobile to pc.
     * 
     * @param serverUrl Full bluetooth server address.
     */
    public void setupBluetoothAppender (String serverUrl){
    	//#ifdef LOGS
        BluetoothSerialAppender appender = new BluetoothSerialAppender(serverUrl);
        log.addAppender(appender);
        //#endif
    }
}